<?php



//循环删除目录下的所有文件
function delFileUnderDir($dirName)
{
if ($handle = opendir("$dirName")) {
   while ( false !== ( $item = readdir( $handle ) ) ) {
   if ( $item != "." && $item != ".." ) {
   if ( is_dir( "$dirName/$item" ) ) {
         delFileUnderDir( "$dirName/$item" );
   } else {
   unlink( "$dirName/$item" );
   }
   }
   }
   closedir( $handle );
  }
}




//递归出部门与子部门
function depart_checkbox($id,$top=false){
	if($top == true)
	{$condition = 'org_id<>0 and del=0 and org_id='.$id;}
	else
	{$condition = 'org_id<>0 and del=0 and depart_id<>0 and depart_id='.$id;}
	$list = M('org')->where($condition)->select();
	foreach($list as $k=>$v)
	{
	echo "var tem".$v['id']."=new JsNode('6000|".$v['id']."','".$v['org_name']."','org_depart');tem".$id.".add(tem".$v['id'].");";
	//递归写
	depart_checkbox($v['id']);	
	}
	}
//获取公司名称
function get_companyname($id)
{
$list = M('company')->where('id='.$id)->find();	
if($list)
{
	return $list['company_name'];
}
else
{
	return '匿名公司';
}	
}
	
//生成11位随机数
function randstr($len=11) { 
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 
// characters to build the password from 
mt_srand((double)microtime()*1000000*getmypid()); 
// seed the random number generater (must be done) 
$password=''; 
while(strlen($password)<$len) 
$password.=substr($chars,(mt_rand()%strlen($chars)),1); 
return $password; 
}
//转换人民币大写
function cny($ns) { 
    static $cnums=array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"), 
        $cnyunits=array("圆","角","分"), 
        $grees=array("拾","佰","仟","万","拾","佰","仟","亿"); 
    list($ns1,$ns2)=explode(".",$ns,2); 
    $ns2=array_filter(array($ns2[1],$ns2[0])); 
    $ret=array_merge($ns2,array(implode("",_cny_map_unit(str_split($ns1),$grees)),"")); 
    $ret=implode("",array_reverse(_cny_map_unit($ret,$cnyunits))); 
    return str_replace(array_keys($cnums),$cnums,$ret); 
} 
function _cny_map_unit($list,$units) { 
    $ul=count($units); 
    $xs=array(); 
    foreach (array_reverse($list) as $x) { 
        $l=count($xs); 
        if ($x!="0" || !($l%4)) $n=($x=='0'?'':$x).($units[($l-1)%$ul]); 
        else $n=is_numeric($xs[0][0])?$x:''; 
        array_unshift($xs,$n); 
    } 
    return $xs; 
} 



		
		
?>